"""
新表结构的模型定义
"""
from . import db
from sqlalchemy import func
from datetime import datetime


class DigitalEmployeeSkills(db.Model):
    """员工技能表"""
    __tablename__ = "digital_employee_skills"
    id = db.Column(db.BigInteger, primary_key=True, comment='主键id')
    parent_id = db.Column(db.BigInteger, nullable=True, comment='父级id')
    name = db.Column(db.String(255), nullable=True, comment='技能名称')
    level = db.Column(db.BigInteger, nullable=True, comment='结构等级')
    nursing_level = db.Column(db.String(50), nullable=True, comment='技能等级')
    sort = db.Column(db.String(20), nullable=True, comment='排序值')
    create_dept = db.Column(db.BigInteger, nullable=True, comment='创建部门')
    create_by = db.Column(db.BigInteger, nullable=True, comment='创建者')
    create_time = db.Column(db.DateTime, nullable=True, onupdate=func.now(), comment='创建时间')
    update_by = db.Column(db.BigInteger, nullable=True, comment='更新者')
    update_time = db.Column(db.DateTime, nullable=True, comment='更新时间')
    remake = db.Column(db.String(255), nullable=True, comment='备注')

    def __repr__(self):
        return f"<DigitalEmployeeSkills {self.id} {self.name} {self.nursing_level}>"


class CareElderDemand(db.Model):
    """老人需求表"""
    __tablename__ = "care_elder_demand"
    id = db.Column(db.BigInteger, primary_key=True, autoincrement=True, comment='id')
    elder = db.Column(db.String(255), nullable=True, comment='老人id')
    elder_name = db.Column(db.String(255), nullable=True, comment='老人姓名')
    gender = db.Column(db.Integer, nullable=True, comment='性别(0女 1男)')
    time_slots = db.Column(db.String(50), nullable=True, comment='时间段')
    actions = db.Column(db.String(50), nullable=True, comment='护理动作id')
    caregiver = db.Column(db.String(255), nullable=True, comment='护理员')
    arrange = db.Column(db.String(255), nullable=False, default='1', comment='参与护理员照护安排(1表示参与，0表示不参与)')

    def __repr__(self):
        return f"<CareElderDemand {self.id} {self.elder} {self.elder_name} arrange:{self.arrange}>"


class CareGbNursingAction(db.Model):
    """国标对应护理动作表"""
    __tablename__ = "care_gb_nursing_action"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='主键id')
    pid = db.Column(db.Integer, nullable=True, comment='父级id')
    name = db.Column(db.String(255), nullable=True, comment='护理动作')
    level = db.Column(db.Integer, nullable=True, comment='护理级别')
    nursing_id = db.Column(db.String(50), nullable=True, comment='对应护理id')

    def __repr__(self):
        return f"<CareGbNursingAction {self.id} {self.name} level:{self.level}>"


class AppUser(db.Model):
    """用户信息表"""
    __tablename__ = "app_user"
    user_id = db.Column(db.BigInteger, primary_key=True, comment='用户ID')
    tenant_id = db.Column(db.String(20), nullable=True, default='000000', comment='租户编号')
    dept_id = db.Column(db.BigInteger, nullable=True, comment='部门id')
    role_id = db.Column(db.BigInteger, nullable=True, comment='角色id')
    user_name = db.Column(db.String(30), nullable=False, comment='用户账号')
    nick_name = db.Column(db.String(30), nullable=False, comment='用户昵称')
    user_type = db.Column(db.String(10), nullable=True, default='app_user', comment='用户类型（app_user系统用户）')
    email = db.Column(db.String(50), nullable=True, default='', comment='用户邮箱')
    phone_number = db.Column(db.String(11), nullable=True, default='', comment='手机号码')
    face_url = db.Column(db.String(255), nullable=True, comment='人脸识别地址')
    sex = db.Column(db.String(1), nullable=True, default='0', comment='用户性别（0男 1女 2未知）')
    avatar = db.Column(db.BigInteger, nullable=True, comment='头像地址')
    password = db.Column(db.String(500), nullable=True, default='', comment='密码')
    salt = db.Column(db.String(255), nullable=True, comment='盐字符串')
    system_type = db.Column(db.String(50), nullable=True, comment='系统标识')
    status = db.Column(db.String(1), nullable=True, default='0', comment='帐号状态（0正常 1停用）')
    del_flag = db.Column(db.String(1), nullable=True, default='0', comment='删除标志（0代表存在 2代表删除）')
    login_ip = db.Column(db.String(128), nullable=True, default='', comment='最后登录IP')
    login_date = db.Column(db.DateTime, nullable=True, comment='最后登录时间')
    create_dept = db.Column(db.BigInteger, nullable=True, comment='创建部门')
    create_by = db.Column(db.BigInteger, nullable=True, comment='创建者')
    create_time = db.Column(db.DateTime, nullable=True, comment='创建时间')
    update_by = db.Column(db.BigInteger, nullable=True, comment='更新者')
    update_time = db.Column(db.DateTime, nullable=True, comment='更新时间')
    remark = db.Column(db.String(500), nullable=True, comment='备注')
    task_id = db.Column(db.BigInteger, nullable=True, comment='任务id')
    chat_identity = db.Column(db.String(2), nullable=True, comment='xchat身份（0亲属 1护理员）')

    def __repr__(self):
        return f"<AppUser {self.user_id} {self.user_name} {self.nick_name}>"
